﻿using Microsoft.EntityFrameworkCore;
using swiftCode.Bbs.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Repositories.EfContext
{
    public class SwiftCodeBbsContext : DbContext
    {
        public SwiftCodeBbsContext() 
        {
            
        }

        public SwiftCodeBbsContext(DbContextOptions<SwiftCodeBbsContext> options) : base(options)
        {
            
        }

        public DbSet<Article> Articles { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Article>().Property(p => p.Title).HasMaxLength(200);
            modelBuilder.Entity<Article>().Property(p => p.Submitter).HasMaxLength(50);
            modelBuilder.Entity<Article>().Property(p => p.Category).HasMaxLength(100);
            modelBuilder.Entity<Article>().Property(p => p.Content).HasMaxLength(2000);
            modelBuilder.Entity<Article>().Property(p => p.Remark).HasMaxLength(200);
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySQL("server=localhost;database=SwiftCodeBbs;user=root;password=whx1004;Port=3306");
        }
    }
}
